stage.set_background("moon")
sprite = codesters.Sprite("hedgehog", 0, -210)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_display = codesters.Display(score, -210, -210)
time = 60
#my_display = codesters.Display(my_var, x, y)
time_display = codesters.Display(time, 210, -210)
def left_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation+3)
# add other actions...
stage.event_key("left", left_key)
def right_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation-3)
# add other actions...
stage.event_key( "right", right_key)
t = codesters.Teacher()
func = t.find_text('def')
call = t.find_function('event')
globs = t.find_text('global')
try:
tval1 = func[2][1]
except:
tval1 = "DNE"
try:
spin = t.find_function("turn_left")
except:
spin = "DNE"
try:
def_line = int(func[2][0])
def_line_indent = t.get_indent_at_line(def_line)
except:
def_line = -1
def_line_indent = -1
try:
call_line = int(call[2][0])
call_line_indent = t.get_indent_at_line(call_line)
except:
call_line = -1
call_line_indent = -1
try:
tval2a = int(globs[0][0])
tval2b = t.get_indent_at_line(tval2a)
tval2c = globs[0][1].replace('global', '').replace(" ", '')
except:
tval2a = -1
tval2b = -1
tval2c = "DNE"
t1 = TestObjective()
t1.add_success(len(func) == 3 and "interval" in tval1 and def_line_indent == 0 and call_line_indent == 0, "Great job!")
t1.add_failure(len(func) < 3, "Did you add an Interval event?")
t1.add_failure(len(func) == 3 and "interval" not in tval1, "Oops! Did you add an Interval event?")
t1.add_failure(def_line_indent > 0 or call_line_indent > 0, "Oops! Make sure you interval event is NOT indented inside another event.")
t2 = TestObjective()
t2.add_success(len(spin) == 0, "Great job!")
t2.add_failure(len(spin) != 0, "Make sure you delete the .turn_left() command in your event!")
t3 = TestObjective()
t3.add_success(tval2a != -1 and tval2b == 4 and tval2c == "time" and def_line <tval2a < call_line, "Great job!")
t3.add_failure(tval2a == -1, "Did you add Global Variable to your event?")
t3.add_failure(tval2b < 4, "Make sure your global command is indented 4 spaces in your interval event.")
t3.add_failure(tval2b > 4, "Make sure your .global command is indented only 4 spaces inside your interval event.")
t3.add_failure(not (def_line <tval2a < call_line), "Make sure your global command is inside your interval event.")
t5 = TestObjective()
t5.add_failure(len(call) != 3, "Oops! Did you delete any event handlers?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t5])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)